<!DOCTYPE html>
<html>
<head>
	<title></title>
	<!--[if lt IE 9]>
	<meta http-equiv="refresh" content="0;ie.html" />
	<![endif]-->

	<link rel="shortcut icon" href="__STATIC__/layout/favicon.ico"> <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
	<link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
	<link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
	<link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
      <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
	<script src="__STATIC__/layout/js/jquery.min.js"></script>
	<!-- Sweet Alert -->
	<link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<!-- Sweet alert -->
	<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
	<!-- layer javascript -->
	<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
</head>
<body class="white-bg" style="color:#333;padding:3px;">
<div class="page-heade">
	<h2 class="title_color text-center">城市类别管理</h2>
</div>
	<div class="padding-10">
		<span class="lr_5"></span><a href="javascript:;" class="btn btn-w-m btn-info" id="new">增加</a>
	</div>
	<div class="ibox-content" style="padding: 10px">

		<form role="form" id="form1" class="form-inline" method="get" action="{:url('index')}">
			<strong>模糊查询:</strong>
			<div class="form-group">
				<label for="search2">类别名称</label>
				<input type="text" name="title" value="{$title}" placeholder="请输入类别名称" id="search2" class="form-control">
			</div>

			<button class="btn btn-info" type="submit">查询</button>
			<button class="btn btn-info" type="reset" id="reset">清空查询条件</button>
		</form>
		<script>
			$(function () {
				$('#reset').on('click',function () {
					document.getElementById('search2').value = ''
					$('#form1').submit()
					return false
                })
            })
		</script>
	</div>
	<div class="padding-10">

		<table class="table table-striped table-bordered table-hover bud_hei text-center" id="editable">
			<thead>
			<tr class="info">
				<th class="text-center">类别名称</th>
				<th class="text-center">排序</th>
				<th class="text-center">创建人</th>
				<th class="text-center">创建时间</th>
				<th class="text-center">修改人</th>
				<th class="text-center">修改时间</th>
				<th class="text-center">操作</th>
			</tr>
			</thead>
			<tbody>
			{volist name="data" id="row"}
			<tr class="gradeX">
				<td>{$row.title}</td>
				<td>{$row.sort}</td>
				<td>{$row.cusername}</td>
				<td>{$row.ctime}</td>
				<td>{$row.pusername}</td>
				<td>{$row.ptime}</td>
				<td class="center">
					<a href="javascript:;" data-id="{$row.id}" class="shezhi">设置城市</a>&nbsp;&nbsp;
					<a href="javascript:;" data-id="{$row.id}" data-title="{$row.title}" data-sort="{$row.sort}" data-brief="{$row.brief}" class="xiugai">修改</a>&nbsp;&nbsp;<a href="javascript:;" data-id="{$row.id}" class="shanchu">删除</a>
				</td>
			</tr>
			{/volist}

			</tbody>

		</table>
		<div class="row text-center" id="pageText" style="padding: 0;margin: 0;">
		<div class="col-sm-6 text-left"><div class="padding-10 countSize">共{$count}条记录，{$maxpage}页&nbsp;&nbsp;</div></div>
		<div class="col-sm-6 text-right">{$page}</div>
	</div>
	</div>

</body>
</html>
<script>
    $(function () {
        $('.shezhi').on('click',function () {
            var id = $(this).data('id')
            //iframe层-父子操作
            var index = layer.open({
                type: 2,
                title: '设置城市',
                area: ['400px', '500px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{:url("setcity")}?id='+id
            });
            layer.full(index);
            return false
        })
        //新增
        $('#new').on('click',function () {
            $('body').append('<div class="channel_popbox" id="channel_popbox">' +
                '<div class="channel_pop_content ibox" style="height:350px;margin-top:-175px;"><div class="ibox-header"><button style="position: absolute;right: 7px;top: 3px;" type="button" class="close" data-dismiss="modal"><span aria-hidden="true" style="font-size:28px;">×</span><span class="sr-only">关闭</span>\n' +
                '</button><h2 style="text-align:center;" class="title_color">新增</h2></div>' +
                '<div class="ibox-content">' +
                '<form role="form" id="formadd" method="post" action="{:url("add")}">\n' +
                '<div class="form-group">\n' +
                '<label>类别名称:</label>\n' +
                '<input name="title" type="text" placeholder="类别名称" class="form-control">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label>排序:</label>\n' +
                '<input name="sort" type="text" placeholder="排序" class="form-control">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label>描述:</label>\n' +
                '<textarea name="brief" placeholder="描述" class="form-control" id="" cols="30" rows="5"></textarea>\n' +
                '</div>\n' +
                 '<div class="text-center" style="padding:20px 0">\n' +
                '<input class="btn btn-sm btn-primary" type="submit" id="tijiao" value="提 交">\n' +
                '</div>\n' +
                '</form>' +
                '</div>' +
                '</div>' +
                '</div>')
        })
        $('body').on('click','#channel_popbox .close',function () {
            $('#channel_popbox').remove()
        })
        $('body').on('click','#channel_popbox .channel_pop_content',function () {
            return false
        })
        $('body').on('click','#channel_popbox #tijiao',function () {
            var form =  $('#channel_popbox #formadd')
            var data = form.serialize()
            $.ajax({
                'type':'post',
                'url':form.attr('action'),
                'data':data,
                'dataType':'json',
                'success':function (data) {
                    if(data.success){
                        swal({
                            title: data.msg,
                            type: "success"
                        },function(){
                            location.reload()
						});

                    }else
                        swal({
                            title: data.msg,
                            type: "warning"
                        });
                }
            })
			return false
        })
		//修改
		$('.xiugai').on('click',function () {
		    var id = $(this).data('id')
		    var title = $(this).data('title')
		    var brief = $(this).data('brief')
		    var sort = $(this).data('sort')
            $('body').append('<div class="channel_popbox" id="channel_popbox">' +
                '<div class="channel_pop_content ibox" style="height:350px;margin-top:-175px;">' +
                '<div class="ibox-header"><button style="position: absolute;right: 7px;top: 3px;" type="button" class="close" data-dismiss="modal"><span aria-hidden="true" style="font-size:28px;">×</span><span class="sr-only">关闭</span>\n' +
                '</button><h2 style="text-align:center;" class="title_color">修改</h2></div>' +
                '<div class="ibox-content">' +
                '<form role="form" id="formadd" method="post" action="{:url("update")}">\n' +
                '<input type="hidden" name="id" value="'+id+'">' +
                '<div class="form-group">\n' +
                '<label>类别名称:</label>\n' +
                '<input name="title" type="text" placeholder="类别名称" class="form-control" value="'+title+'">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label>排序:</label>\n' +
                '<input name="sort" type="text" placeholder="排序" class="form-control" value="'+sort+'">\n' +
                '</div>\n' +
                '<div class="form-group">\n' +
                '<label>描述:</label>\n' +
                '<textarea name="brief" placeholder="描述" class="form-control" id="" cols="30" rows="5">'+brief+'</textarea>\n' +
                '</div>\n' +
                 '<div class="text-center" style="padding:20px 0">\n' +
                '<input class="btn btn-sm btn-primary" type="submit" id="tijiao" value="提 交">\n' +
                '</div>\n' +
                '</form>' +
                '</div>' +
                '</div>' +
                '</div>')
        })
		//删除
        $('.shanchu').click(function () {
            var id = $(this).data('id')
            swal({
                title: "您确定要删除这条信息吗",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: false
            }, function () {
                $.ajax({
                    'type':'post',
                    'url':'{:url("delete")}',
                    'data':{'id':id},
                    'dataType':'json',
                    'success':function (data) {
                        if(data.success){
                            location.reload()
                        }else
                            swal(data.msg, "", "error");
                    }
                })

            });
        });

    })
</script>